﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Publicuse.Entity.AttributeUtil.Validate
{
    /// <summary>
    ///长度验证
    /// </summary>
    public class LengthAttribute : BaseValidateAttribute
    {
        private int _iMin = 0;
        private int _iMax = 0;
        private string remark = null;
        public string GetRemark { get { return this.remark; } }
        /// <summary>
        /// 左边闭区间  右边开区间
        /// </summary>
        /// <param name="min">包含</param>
        /// <param name="max">不包含</param>
        public LengthAttribute(int min, int max,string remark)
        {
            this._iMin = min;
            this._iMax = max;
            this.remark = remark;
        }

        public override bool Validate(object oValue)
        {
            if (oValue != null && !string.IsNullOrEmpty(oValue.ToString()))
            {
                return oValue.ToString().Length >= this._iMin && oValue.ToString().Length < this._iMax;
            }
            else
            {
                return true;
            }
        }
    }
}
